#pragma once
#include <string>
#include <vector>
#include <string>
#include "StringUtility.h"

class TypeConvert
{
public:
// 	int ToInt(const std::wstring &s);
// 	float ToFloat(const std::wstring &s);
// 	std::wstring ToString(const std::wstring &s);
	
	template<class T>
	static T To(const std::wstring &s)
	{
		std::wstringstream ss(s);
		T value;
		ss >> value;
		return value;
	}

// 	template<class T>
// 	T To(const std::wstring &s, T *convertFunc(const std::wstring &s, T))
// 	{
// 
// 	}

	template<class T>
	static bool TryToArray(const std::wstring &s, std::vector<T> &values)
	{
		size_t index = s.find(':');
		if (index == std::wstring::npos)
		{
			return false;
		}
		size_t len = To<size_t>(s.substr(0, index));

		std::vector<std::wstring> items = StringUtility::Split(s.substr(index+1), ',');
		if (items.size() != len)
		{
			return false;
		}

		values.clear();

		for (std::vector<std::wstring>::iterator it = items.begin();
				it != items.end(); ++it)
		{
			values.push_back(To<T>(*it));
		}

		return true;
	}
};

